﻿@using Gx.Model.Entity;
@using Gx.Model.Enums;
@model LKZeroWarehouseContract
@{
    ViewBag.Title = "新建零仓合同";
    Layout = "~/Views/Shared/InfoMaste.cshtml";
    //List<M_DictInfo> dictList = ViewData["M_DictInfo"] as List<M_DictInfo>;
    //List<G_OrderTypeInfo> otList = ViewData["G_OrderTypeInfo"] as List<G_OrderTypeInfo>;
    //List<G_ModeInfo> mList = ViewData["G_ModeInfo"] as List<G_ModeInfo>;
}
<link href="~/Content/css/custome.css" rel="stylesheet" />
<div title="新建零仓合同" style="width:auto; height:auto; padding-left:5px; font-size:14px;  ">
    <div class="ftitle">
        <a href="javascript:" class="easyui-linkbutton" iconCls="icon-ok" style="height:32px" onclick="saveData()">保存</a>
        <a href="/LKWarehouseContract/LKZeroWarehouseContractList" class="easyui-linkbutton" iconCls="icon-back" style="height:32px">返回</a>
    </div>
    <form id="fm" method="post" novalidate>
        <div class="ftitle">基础信息</div>
        <input type="hidden" id="hidFileId" />
        <div class="fitem1">
            <label>
                单据编号:
            </label>
            <input class="easyui-textbox" readonly="readonly" value="系统自动生成" style="width: 173px; height: 30px;">
            <label>
                开单日期:
            </label>
            <input class="easyui-datebox" name="ContractTime" id="ContractTime" value="@Model.ContractTime" style="width: 173px; height: 30px; " data-options="required:true">
            <label>
                天数:
            </label>
            <input name="Days" id="Days" class="easyui-numberbox" value="@Model.Days" style="width: 173px; height: 30px;" />
            @*<label>
                客户编号:
            </label>
            <select class="easyui-combogrid" style="width: 173px; height: 30px;" name="CustomerId" id="CustomerId"></select>
            <label>
                客户名称:
            </label>
            <input name="CustomerName" id="CustomerName" class="easyui-textbox" style="width: 173px; height: 30px;" readonly="readonly" />*@
        </div>
        @*<div class="fitem1">
            <label>
                开单日期:
            </label>
            <input class="easyui-datebox" name="ContractTime" id="ContractTime" value="@Model.ContractTime" style="width: 173px; height: 30px; " data-options="required:true">
            <label>
                开始日期:
            </label>
            <input class="easyui-datebox" name="BeginTime" id="BeginTime" style="width: 173px; height: 30px; " data-options="required:true">
            <label>
                结束日期:
            </label>
            <input class="easyui-datebox" name="EndTime" id="EndTime" style="width: 173px; height: 30px; " data-options="required:true">
        </div>*@
        <div class="fitem1">
            <label>
                计费单位:
            </label>
            <input name="ChargingUnit" id="ChargingUnit" value="@Model.ChargingUnit" class="easyui-combobox" style="width: 173px; height: 30px;" />
            <label>
                不足n吨算n吨:
            </label>
            <input name="Tonnage" id="Tonnage" value="@Model.Tonnage" class="easyui-numberbox" data-options="required: true" style="width: 173px; height: 30px;" autocomplete="off" />
            <label>
                按吨操作:
            </label>
            <input class="easyui-switchbutton" id="sbIsByTon" data-options="onText:'是',offText:'否'">

        </div>

        <div class="fitem1">
            <label>
                冷藏单价:
            </label>
            <input name="ColdUnitPrice" id="ColdUnitPrice" value="@Model.ColdUnitPrice" class="easyui-numberbox" data-options="required: true,precision:'2'" style="width: 173px; height: 30px;" autocomplete="off" />
            <label>
                冷藏算法
            </label>
            <input name="ColdAlgorithm" id="ColdAlgorithm" value="@Model.ColdAlgorithm" class="easyui-combobox" style="width: 173px; height: 30px;" />
            @*<label>
                周期:
            </label>
            <input name="Cycle" id="Cycle" class="easyui-numberbox" value="@Model.Cycle" style="width: 173px; height: 30px;" />*@

        </div>
        @*<div class="fitem1">
            <label>
                图片:
            </label>
            <input id="filebox" class="easyui-filebox" name="file" data-options="buttonText:'选择文件',accept:'image/*',onChange:fileChange" />
        </div>*@
        <div class="fitem1">
            <label>
                备注:
            </label>

            <input name="Remark" id="Remark" class="easyui-textbox" multiline="true" style="width: 500px; height: 60px; vertical-align: top" />
        </div>
        <div class="ftitle">默认杂费设置</div>
        <div id="Wl">
            <div style="height: 300px; ">
                <a href="javascript:" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="addDom()">添加</a>
                <table class="gridtable">
                    <thead>
                        <tr>
                            <th>费用类别</th>
                            <th>价格</th>
                            <th>单位</th>
                            <th>在入库单显示</th>
                            <th>在出库单显示</th>
                            <th>在调仓单显示</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
        @Html.Partial("~/Views/Shared/_CreateUserAndModifyUser.cshtml")
    </form>
    @*<div id="customerselecttoolbar2">
        <input id="SelectCustomerText2" class="easyui-textbox " style="width: 173px; height: 30px;" />
        <a href="javascript:" class="easyui-linkbutton" plain="true" iconcls="icon-search" onclick="querycustomer2()">查询</a>
    </div>*@
</div>

<script src="~/Js/Global.js?v=20240706"></script>
<script type="text/javascript">

    $(function () {
        InitChargingUnitCombobox();
        InitColdAlgorithmCombobox();
        //InitCustomer();
        $('#sbIsByTon').switchbutton({ checked: @Html.Raw(Model.IsByTon ? "true" : "false") });
    });

    var domId = 1;
    function addDom() {
        $.post("/LKWarehouseContract/_AddLKZeroWarehouseContract", { domId: domId }, function (html) {
            $.messager.progress('close');
            $(".gridtable").append(html);
            $.parser.parse($("#" + domId));
            InitCostTypesCombogrid(domId);
            domId = Number(domId) + 1;
        });
    }

    function delDom(domId) {
        $("#" + domId).remove();
    }

    function querycustomer2() {
        $("#CustomerId").combogrid("grid").datagrid("reload", { "Customer": $("#SelectCustomerText2").val() });
    }


    function saveData() {
        var validate = $("#fm").form("validate")
        if (!validate) {
            return;
        }
        var isByTon = $('#sbIsByTon').switchbutton('options').checked;
        var data = {
            //"CustomerId": $("#CustomerId").combobox('getValue'),
            //"CustomerName": $("#CustomerName").textbox('getValue'),
            "ContractTime": $("#ContractTime").datebox('getValue'),
            //"BeginTime": $("#BeginTime").datebox('getValue'),
            //"EndTime": $("#EndTime").datebox('getValue'),
            "Tonnage": $("#Tonnage").numberbox('getValue'),
            "ChargingUnit": $("#ChargingUnit").combobox('getValue'),
            "ColdUnitPrice": $("#ColdUnitPrice").numberbox('getValue'),
            "ColdAlgorithm": $("#ColdAlgorithm").combobox('getValue'),
            //"Cycle": $("#Cycle").numberbox('getValue'),
            "Days": $("#Days").numberbox('getValue'),
            "Remark": $("#Remark").val(),
            "IsByTon": isByTon

        };
        var CostList = new Array();
        for (var i = 1; i < domId; i++) {
            var obj = $("#CostType" + i);
            if (obj.length == 0) {
                continue;
            }
            var costTypeId = obj.combogrid('getValue');
            if ($.trim(costTypeId) == "") {
                continue;
            }
            var CostTypeId = $("#CostType" + i).combobox('getValue');
            var CostType = $("#CostType" + i).combobox('getText');
            var Price = $("#Price" + i).numberbox('getValue');
            var Unit = $("#Unit" + i).textbox('getValue');
            var InStorage = $("#sbInStorage" + i).switchbutton('options').checked;
            var OutStorage = $("#sbOutStorage" + i).switchbutton('options').checked;
            var TransferStorage = $("#sbTransferStorage" + i).switchbutton('options').checked;


            //if (CostType == "" || Price == "" || Unit == "") {
            //    Helper.Show("请检查第" + i + "行费用信息");
            //    return;
            //}
            var cost = {
                "CostTypeId": CostTypeId,
                "CostType": CostType,
                "Price": Price,
                "Unit": Unit,
                "InStorage": InStorage,
                "OutStorage": OutStorage,
                "TransferStorage": TransferStorage
            };
            CostList.push(cost);
        }
        var d = JSON.stringify({ LKZeroWarehouseContract: data });
        $.messager.progress({
            title: '请稍后',
            msg: '数据保存中...',
        });
        window.setTimeout(function () {
            $.ajax({
                url: '/LKWarehouseContract/AddLKZeroWarehouseContract',
                type: "post",
                data: JSON.stringify({ LKZeroWarehouseContract: data, CostList: CostList, AttachmentId: $("#hidFileId").val() }),
                contentType: 'application/json; charset=utf-8',
                success: function (json) {
                    $.messager.progress('close');
                    Helper.Show(json.Msg);
                    if (json.Success) {
                        setTimeout(function () { window.location.href = "/LKWarehouseContract/LKZeroWarehouseContractList"; }, 2000);
                    }
                }
            });
        }, 2000);


    }
</script>

